import VuiDropdownItem from '.';
import VuiSvgIcon from '../../icon/svg-icon';

/**
 * 下拉菜单选项-可选中
 */
export default class VuiDropdownToggleItem extends VuiDropdownItem {
  constructor(id, title, checked = false) {
    const icon = VuiSvgIcon.newInstance('checked');
    super(id, title, icon);

    this._config.checked = checked;
  }

  initUI() {
    super.initUI();
    this.setChecked();
  }

  setChecked(value) {
    const config = this._config;
    if (value) {
      config.icon?.show();
      config.checked = true;
      if (this._group) {
        this._group.cleanBrother(this);
      }
    } else {
      config.icon?.hide();
      config.checked = false;
    }
  }

  getChecked() {
    return this._config.checked;
  }

  toggleChecked() {
    const config = this._config;
    this.setChecked(!config.checked);
  }

  setGroup(group) {
    this._group = group;
  }
}
